package org.raymond.iworks.gateway.controller;

import cn.hutool.crypto.asymmetric.RSA;
import lombok.extern.slf4j.Slf4j;
import org.raymond.iworks.apis.common.Result;
import org.raymond.iworks.commons.constants.CommonConstants;
import org.raymond.iworks.core.constants.SecurityComponets;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class GatewayController {
    private static final boolean encryptEnable = CommonConstants.ENCRYPT_ENABLE;
    private static final RSA rsa = SecurityComponets.DEFAULT_ENCRYPTOR;

    @GetMapping("/common/config/system")
    public Result systemConfig(){
        String publicKeyBase64 = rsa.getPublicKeyBase64();
        if(log.isDebugEnabled()) {
            log.debug("encryptEnable:{}, publicKey:{}", encryptEnable, publicKeyBase64);
        }
        Map<String, Object> systemConfig = new HashMap<>();
        systemConfig.put("encryptEnable", encryptEnable);
        systemConfig.put("publicKey", publicKeyBase64);
        return Result.success(systemConfig);
    }
}
